import os
import os.path
import tempfile
from unittest import TestCase, mock
from mock_demo.module0 import rm
from mock_demo import module0
import mock_demo


class RmTestCase(TestCase):
    def setUp(self):
        self.tmpfilepath = os.path.join(tempfile.gettempdir(), "tmp-testfile")
        with open(self.tmpfilepath, "w") as f:
            f.write("Delete me!")
        
    def test_rm(self):
        self.assertTrue(os.path.isfile(self.tmpfilepath), "file %s not exists" % self.tmpfilepath)
        rm(self.tmpfilepath)
        self.assertFalse(os.path.isfile(self.tmpfilepath), "Failed to remove the file.")


class RmMockTest(TestCase):
    @mock.patch('mock_demo.module0.os.path')
    @mock.patch('mock_demo.module0.os')
    def test_rm(self, mock_os, mock_path):
        mock_path.isfile.return_value = False
        rm("any path")
        self.assertFalse(mock_os.remove.called, "Failed to not remove the file if not present.")

        mock_path.isfile.return_value = True
        rm("any path")
        mock_os.remove.assert_called_with("any path")
